package us.mooresr.webtroopmanager.client.activity;

import us.mooresr.webtroopmanager.client.ClientFactory;
import us.mooresr.webtroopmanager.client.SecurityManager;
import us.mooresr.webtroopmanager.shared.Privilege;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.user.client.ui.AcceptsOneWidget;

public class MyActivity implements Activity {
	Place place;
	ClientFactory clientFactory;

	@Override
	public String mayStop() {
		return null;
	}

	@Override
	public void onCancel() {
	}

	@Override
	public void onStop() {
	}

	@Override
	public void start(AcceptsOneWidget panel, EventBus eventBus) {
				
	}
	
	public MyActivity(ClientFactory clientFactory) {
		this.clientFactory = clientFactory;	
		this.place = null;
	}
	
	public MyActivity(Place place, ClientFactory clientFactory) {
		this.clientFactory = clientFactory;
		this.place = place;
	}

	public void goTo(Place place) {
		clientFactory.getPlaceController().goTo(place);		
	}
	
	
	public Boolean hasPermission(Privilege priv) {
		SecurityManager securityManager = clientFactory.getSecurityManager();
		return securityManager.hasPrivilege(priv);
	}
	
	public Boolean isAllowed(Privilege priv, Long objectId) {
		SecurityManager securityManager = clientFactory.getSecurityManager();
		return securityManager.isAllowed(priv, objectId);
	}
	
}
